package com.haoran.dwz.domain.entities;

import java.text.ParseException;
import java.util.Date;

import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;

import com.haoran.dwz.common.util.DateUtils;

import io.swagger.annotations.ApiModelProperty;

public abstract class PeriodFilterEntity extends PaginationEntity{
    
    @Transient
    @ApiModelProperty(value="时间区间过滤 约定格式yyyy-MM-dd HH:mm:ss - yyyy-MM-dd HH:mm:ss")
    private String filterTime;

	public String getFilterTime() {
		return StringUtils.trimToEmpty(filterTime);
	}

	public void setFilterTime(String filterTime) {
		this.filterTime = filterTime;
	}
    
    public Date getStartDateTime() {
		try {
			String filterTime2 = getFilterTime();
			if(StringUtils.isBlank(filterTime2)) {
				return null;
			}
			String startDateTime = filterTime2.substring(0, 19);
			return DateUtils.parse(startDateTime, DateUtils.DATE_TIME_PATTERN);
		} catch (ParseException e) {
			return null;
		}
    }
    
    public Date getEndDateTime() {
		try {
			String filterTime2 = getFilterTime();
			if(StringUtils.isBlank(filterTime2)) {
				return null;
			}
			String endDateTime = getFilterTime().substring(getFilterTime().length()-19, getFilterTime().length());
			return DateUtils.parse(endDateTime, DateUtils.DATE_TIME_PATTERN);
		} catch (ParseException e) {
			return null;
		}
    }
}
